<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      permission="user:exportManagement:view"
    ></Ht-search-form>
    <ht-table
      ref="dataTable"
      :multi-select="true"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="reqConfig"
    >
      <template v-slot:operate>
        <el-table-column
          :label="$t('common.operation')"
          align="center"
          width="160"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              v-hasPermi="['user:exportManagement:download']"
              size="mini"
              type="text"
              @click="handleAction('download', scope.row)"
              >{{ $t("authority.exportManagement.form.download") }}
            </el-button>
            <el-button
              v-hasPermi="['user:exportManagement:remove']"
              size="mini"
              type="text"
              @click="handleAction('del', scope.row)"
              >{{ $t("common.delete") }}
            </el-button>
          </template>
        </el-table-column>
      </template>
    </ht-table>
  </div>
</template>

<script>
import {
  apiUrlConfig,
  download,
  delExportManagement,
} from "@/api/authority_app/exportManagement/exportManagement";
import { listPageMixin } from "@/libs/listPageMixin";
import { baseUrlConfig } from "@/api/authority_app/base";

export default {
  name: "exportManagement",
  components: {},
  mixins: [listPageMixin],
  data() {
    return {
      //查询参数
      queryParams: {
        ossName: "",
      },
      formOptions: [],
      reqConfig: apiUrlConfig,
      tableBindColumns: [
        { label: `ID`, prop: "id", visible: false },
        {
          label: this.$t("authority.exportManagement.form.ossId"),
          prop: "ossId",
        },
        { label: this.$t("authority.exportManagement.form.uri"), prop: "uri" },
        {
          label: this.$t("authority.exportManagement.form.ossName"),
          prop: "ossName",
        },
        {
          label: this.$t("authority.exportManagement.form.ossType"),
          prop: "ossType",
        },
        {
          label: this.$t("authority.exportManagement.form.credentialId"),
          prop: "credentialId",
        },
        {
          label: this.$t("authority.exportManagement.form.createTime"),
          prop: "createTime",
        },
        {
          label: this.$t("authority.exportManagement.form.updateTime"),
          prop: "updateTime",
        },
      ],
      opButtonList: () => {
        return [
          {
            label: this.$t("common.delete"),
            type: "danger",
            icon: "el-icon-delete",
            permission: "user:exportManagement:remove",
            actionType: "del",
          },
        ];
      },
    };
  },
  mounted() {
    const formOptions = [
      {
        type: "input",
        prop: "ossName",
        defaultAttr: {
          size: "small",
          label: this.$t("authority.exportManagement.form.ossName"),
          placeholder: this.$t("authority.exportManagement.rules.ossNamePLH"),
        },
      },
    ];
    this.formOptions = formOptions;
  },
  methods: {
    handleAction(type, row = {}) {
      switch (type) {
        case "add":
          this.handleAdd();
          break;
        case "download":
          this.handleDownload(row);
          break;
        case "del":
          const id = row.id || this.ids.join(",");
          this.$confirm(
            this.$t("authority.exportManagement.rules.deleteTip"),
            this.$t("authority.exportManagement.form.warning"),
            {
              confirmButtonText: this.$t("common.confirm"),
              cancelButtonText: this.$t("common.cancel"),
              type: "warning",
            }
          )
            .then(function () {
              return delExportManagement(id);
            })
            .then(() => {
              this.doQuery();
              this.msgSuccess(this.$t("common.deleteSuccess"));
            })
            .catch((action) => {});
          break;
        case "update":
          // this.$refs.editConfigDialog.show(row.id);
          this.handleUpdate(row);
          break;
      }
    },
    handleDownload(row) {
      window.open(
        `${baseUrlConfig.downloadFile}?fileId=${row.ossId}&serviceName=${row.fileSvcName}&fileName=${row.ossName}`
      );
    },
  },
};
</script>
